<?php

/*
 * File  : ongkir.php
 * Table : ongkirs
 */
//session_start();
//cek session

if ((!$_SESSION["USRID"] AND !$_SESSION["USRPASS"])) {
    header("location: ../index.php");
    exit();
}
//end
?>
<?php

$aksi = "cms/bab/m_ongkirs/aksi_ongkir.php";
switch ($_GET["opr"]) {

    // Tampil Ongkos Kirim
    default:
        echo "<h2>Ongkos Kirim</h2>";
        echo " <input type=button value='Tambah Ongkos Kirim' onclick=\"window.location.href='?module=ongkir&opr=tambah';\">";
        echo "  <table>";
        echo "   <tr><th>No</th><th>Nama Kota</th><th>Ongkos Kirim</th><th>Aksi</th></tr>";
        $tampil = mysql_query("SELECT * FROM ongkirs ORDER BY ongkir_id DESC");
        $no = 1;
        while ($row = mysql_fetch_array($tampil)) {
            $ongkos = format_rupiah($row["ongkir_harga"]);
            echo "<tr><td>$no</td>";
            echo " <td>" . $row["ongkir_kota"] . "</td>";
            echo " <td align=right>$ongkos</td>";
            echo " <td><a href='?module=ongkir&opr=edit&id=" . $row["ongkir_id"] . "'>Edit</a> | 
	               <a href='" . URLHOST . "$aksi?module=ongkir&opr=hapus&id=" . $row["ongkir_id"] . "'  onClick=\"return confirm('Hapus Ongkos Kirim Wilayah " . $row["ongkir_kota"] . "?')\" >Hapus</a>";
            echo " </td></tr>";
            $no++;
        }
        echo "</table>";
        break;

    // Form Tambah Ongkos Kirim
    case "tambah":
        echo "<h2>Tambah Ongkos Kirim</h2>";
        echo "<form method='POST' action='" . URLHOST . "$aksi?module=ongkir&opr=input'>";
        echo "  <table>";
        echo "  <tr><td>Nama Kota</td><td> : <input type='text' name='in_ongkir_kota'></td></tr>";
        echo "  <tr><td>Ongkos Kirim</td><td> : <input type='text' name='in_ongkir_harga' size=7></td></tr>";
        echo "   <tr><td colspan=2><input type=submit name=submit value=Simpan> <input type=button value=Batal onclick=self.history.back()></td></tr>";
        echo "  </table>";
        echo "</form>";
        break;

    // Form Edit Ongkos Kirim
    case "edit":
        $edit = mysql_query("SELECT * FROM ongkirs WHERE ongkir_id='" . $_GET["id"] . "'");
        $row = mysql_fetch_array($edit);

        echo "<h2>Edit Ongkos Kirim</h2>";
        echo " <form method='POST' action='" . URLHOST . "$aksi?module=ongkir&opr=update'>";
        echo "  <input type='hidden' name='id' value='" . $row["ongkir_id"] . "'>";
        echo "  <table>";
        echo "   <tr><td>Nama Kota</td><td> : <input type='text' name='in_ongkir_kota' value='" . $row["ongkir_kota"] . "'></td></tr>";
        echo "   <tr><td>Ongkos Kirim</td><td> : <input type='text' name='in_ongkir_harga' value='" . $row["ongkir_harga"] . "' size='7'></td></tr>";
        echo "  <tr><td colspan = 2><input type = submit value = Update><input type = button value = Batal onclick = self.history.back()></td></tr>";
        echo "  </table>";
        echo " </form>";
        break;
}
?>
